]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
shell-util: Add a helper method for saving files from HTTP
authorJasper St. Pierre <jstpierre@mecheye.net>
Tue, 28 Jun 2011 00:17:27 +0000 (20:17 -0400)
committerJasper St. Pierre <jstpierre@mecheye.net>
Wed, 6 Jul 2011 16:46:18 +0000 (12:46 -0400)
Unfortunately, gjs cannot handle binary C strings directly from
gobject-introspection. Add a simple workaround method in C to help
us save random files from the web.

https://bugzilla.gnome.org/show_bug.cgi?id=653989

src/shell-util.c
src/shell-util.h

index 3234faf0edbfb3be88717f0db1ea60b293e3f710..ef00f44a531a26e6e9e3caaa4eb54ab6f064715c 100644 (file)
@@ -560,6 +560,29 @@ shell_get_event_state (ClutterEvent *event)
   return state & CLUTTER_MODIFIER_MASK;
 }
 
+/**
+ * shell_write_soup_message_to_stream:
+ * @stream: a #GOutputStream
+ * @message: a #SoupMessage
+ * @error: location to store GError
+ *
+ * Write a string to a GOutputStream as binary data. This is a
+ * workaround for the lack of proper binary strings in GJS.
+ */
+void
+shell_write_soup_message_to_stream (GOutputStream *stream,
+                                    SoupMessage   *message,
+                                    GError       **error)
+{
+  SoupMessageBody *body;
+
+  body = message->response_body;
+
+  g_output_stream_write_all (stream,
+                             body->data, body->length,
+                             NULL, NULL, error);
+}
+
 /**
  * shell_write_string_to_stream:
  * @stream: a #GOutputStream
index 7887f9e89f42d00f188740f1c7f7dc821f884abe..1f431ff625bf4a9fd74462b27c4c0bae86e7ad5c 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <gio/gio.h>
 #include <clutter/clutter.h>
+#include <libsoup/soup.h>
 
 G_BEGIN_DECLS
 
@@ -25,6 +26,10 @@ char    *shell_util_format_date                (const char       *format,
 ClutterModifierType
          shell_get_event_state                 (ClutterEvent     *event);
 
+void     shell_write_soup_message_to_stream    (GOutputStream    *stream,
+                                                SoupMessage      *message,
+                                                GError          **error);
+
 gboolean shell_write_string_to_stream          (GOutputStream    *stream,
                                                 const char       *str,
                                                 GError          **error);